﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CJJ_BlogApiV3.Model
{
    /// <summary>
    /// / 不分页查询
    /// </summary>
    /// <typeparam name="T">泛型类型</typeparam>
    public class ResultList<T> : Result
    {
        /// <summary>
        /// 数据集合对象
        /// </summary>
        public List<T> DataList { get; set; }

        /// <summary>
        /// 返回一个操作成功结构
        /// </summary>
        public static ResultList<T> Success(List<T> value)
        {
            return new ResultList<T>()
            {
                DataList = value,
                IsSucceed = true,
                Message = "成功",
                ErrorCode = 0
            };
        }

        /// <summary>
        /// 返回一个失败的操作结果
        /// </summary>
        /// <param name="message"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public new static ResultList<T> Failure(string message = "", int code = 501)
        {
            return new ResultList<T>
            {
                IsSucceed = false,
                Message = message,
                ErrorCode = code
            };
        }
    }


    /// <summary>
    /// 分页查询对象
    /// </summary>
    /// <typeparam name="T">泛型类型</typeparam>
    public class ResultPage<T> : ResultList<T>
    {

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }

        /// <summary>
        /// 总条数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 返回一个成功的操作结果
        /// </summary>
        public new static ResultPage<T> Success()
        {
            return new ResultPage<T>()
            {
                IsSucceed = true,
                Message = "操作成功",
                ErrorCode = 200
            };
        }

        /// <summary>
        /// 返回一个失败的操作结果
        /// </summary>
        /// <param name="message"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public new static ResultPage<T> Failure(string message = "", int code = 501)
        {
            return new ResultPage<T>
            {
                IsSucceed = false,
                Message = message,
                ErrorCode = code
            };
        }
    }
}
